//1.创建渲染器
let renderer = new THREE.WebGLRenderer({
    antialias:true
});

renderer.setSize(window.innerWidth,window.innerHeight);

renderer.shadowMapEnabled = true; //初始化渲染阴影

document.body.appendChild(renderer.domElement);

//2.创建场景
let scene = new THREE.Scene();

//3.创建相机
let camera = new THREE.PerspectiveCamera(45,window.innerWidth/window.innerHeight,1,1000);

camera.position.y = 20;
camera.position.z = 30;
camera.position.x = -15;

camera.lookAt(scene.position);

scene.add(camera);

//创建辅助线
let axes = new THREE.AxesHelper(100);
scene.add(axes);

//4.物体

//4.1创建平面

//创建几何体
let PlaneGeometry = new THREE.PlaneGeometry(60,20);

let planeMaterial = new THREE.MeshLambertMaterial({
    color:0xcccccc
})

let plane = new THREE.Mesh(PlaneGeometry,planeMaterial);

plane.rotation.x = -0.5*Math.PI;
plane.position.x = 10;
plane.receiveShadow = true;//接收阴影
scene.add(plane);

//4.2 创建3个立方体
let box1Geometry = new THREE.BoxGeometry(5,5,5);

let box1Material = new THREE.MeshBasicMaterial({
    color:0xff0000
})

let box1 = new THREE.Mesh(box1Geometry,box1Material);

box1.position.y = 2.5;
box1.castShadow = true;

//第二个正方体
//加载纹理
let texture = new THREE.TextureLoader().load('./1.jpg',() => {
    renderer.render(scene,camera)
});
//MeshLambertMaterial 是受光照影响的
let box2Material = new THREE.MeshBasicMaterial({
    // color:0x11ffee
    map:texture  //设置材质
})

let box2 = new THREE.Mesh(box1Geometry,box2Material);

box2.position.x = -7;
box2.position.y = 2.5;

box2.castShadow = true; //要产生阴影

//第三个正方体
let box3Material = new THREE.MeshNormalMaterial()

let box3 = new THREE.Mesh(box1Geometry,box3Material);

box3.position.x = 7;
box3.position.y = 2.5;
box3.castShadow = true;
scene.add(box1);

scene.add(box2);

scene.add(box3);

//创建球体
let sphereGeometry= new THREE.SphereGeometry(3,20,20);

let sphereMaterial = new THREE.MeshLambertMaterial({
    color:0x00cccc
})

let sphere = new THREE.Mesh(sphereGeometry,sphereMaterial);

sphere.position.x = 15;
sphere.position.y = 3;
sphere.castShadow = true;
scene.add(sphere);


//创建球体

let sphereMateria2 = new THREE.MeshPhongMaterial({
    color:0x00cccc
})

let sphere2 = new THREE.Mesh(sphereGeometry,sphereMateria2);

sphere2.position.x = 30;
sphere2.position.y = 3;
sphere2.castShadow = true;
scene.add(sphere2);

//添加光照

//环境光 一般都会搭配其他的光源使用
// let light = new THREE.AmbientLight(0xffffff);

// scene.add(light);

//点光源

let pointLight = new THREE.PointLight(0xffffff);

pointLight.position.y = 15;
pointLight.position.x = -5;

pointLight.castShadow = true;

scene.add(pointLight);

renderer.render(scene,camera);